unit selitem;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, StdCtrls, Buttons, ExtCtrls;

type
  TfrmSelItem = class(TForm)
    sGrupo: TDataSource;
    sItem: TDataSource;
    Panel1: TPanel;
    grdGrupo: TDBGrid;
    grdItem: TDBGrid;
    Panel2: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure grdItemDblClick(Sender: TObject);
    procedure sGrupoDataChange(Sender: TObject; Field: TField);
    procedure FormCreate(Sender: TObject);
  private
    function RecuperarIdItem: string;
    procedure EstablecerIdItem (idItem: string);
    //function RecuperarIdGrupo: string;
    procedure EstablecerTipologia (idTipologia: string);
  public
    property idItem: string read RecuperarIdItem write EstablecerIdItem;
    //property idGrupo: string read RecuperarIdGrupo;
    property idTipologia: string write EstablecerTipologia;
    function Entrar : integer;
  end;

var
  frmSelItem: TfrmSelItem;

implementation

uses presupuesto, MDatos, Recursos, main;

{$R *.dfm}

function TfrmSelItem.RecuperarIdItem: string;
begin
  Result := Datos.cItemID_ITEM.AsString;
end;

procedure TfrmSelItem.EstablecerIdItem (idItem: string);
var
  sql: string;
begin
  sql := 'select id_grupo from item where id_item = '+idItem;
  EjecutarSql(Datos.qryVar, sql);
  Datos.cGrupo.Locate('id_grupo', Datos.qryVar.Fields [0].AsInteger, []);
  Datos.cItem.Locate('id_item', idItem, []);
  Datos.qryVar.Close;
end;

procedure TfrmSelItem.EstablecerTipologia(idTipologia: string);
begin
  Datos.cItem.Filter := 'id_tipologia = '+idTipologia;
  Datos.cItem.Filtered := True;
end;

{function TfrmSelItem.RecuperarIdGrupo: string;
begin
  result := Datos.cGrupoID_GRUPO.AsString;
end; }

function TfrmSelItem.Entrar : integer;
begin
  Result := Showmodal;
end;

procedure TfrmSelItem.grdItemDblClick(Sender: TObject);
begin
  ModalResult := mrOK;
end;

procedure TfrmSelItem.sGrupoDataChange(Sender: TObject; Field: TField);
begin
  if  frmSelItem.Visible then
  begin
    Datos.cItem.Close;
    Datos.cItem.CommandText := 'select * from ITEM where ID_GRUPO = '+Datos.cGrupoID_GRUPO.AsString+' and not (ITEM like ''*%'')';
    Datos.cItem.Open;
    //Datos.cItem.Params [0].AsInteger := Datos.cGrupoID_GRUPO.AsInteger;
    {if Datos.cItem.State = dsInactive then
      Datos.cItem.Open
    else
    begin
      Datos.cItem.Close;
      Datos.cItem.Open;
    end;   }
  end;
end;

procedure TfrmSelItem.FormCreate(Sender: TObject);
begin
  Acomodo(frmSelItem);
end;


end.
